<style type="text/css">
    
   .upload-image-box {
        width: 130px;
        height: 90px;
        border: 1px solid rgba(125, 125, 125, .1);
        background: url("__ROOT__/static/theme/img/404_icon.png") no-repeat center center;
        background-size: cover;
    }

</style>
<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label label-required">公司名称</label>
            <div class="layui-input-block">
                {if @$vo.name}

                <input {if $userinfo['db1']['authorize'] =='8'}readonly{/if} name="companyname" value='{$vo.name|default=""}' required placeholder="请输入公司名称" class="layui-input">
                {else}
                <input name="companyname" value=''  required placeholder="请输入公司名称" class="layui-input">
                {/if}
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">公司信用代码</label>
            <div class="layui-input-block">
                {if @$vo.code}

                <input {if $userinfo['db1']['authorize'] =='8'}readonly{/if} name="code" value='{$vo.code|default=""}'  placeholder="公司信用代码" class="layui-input">
                {else}
                <input  readonly name="code" value=''   placeholder="无需填写" class="layui-input">
                {/if}
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label label-required">绑定公司经营者</label>
<!--             <div class="layui-input-block">

               <select  class="layui-select" name="createuid" >
                <option value="">-- 绑定用户 --</option>
                    {foreach $data['userlist'] as $key=>$val}
                    {if @$vo.createuid == $val.id}
                    
                         
                        <option selected value="{$val.id}">{$val.name}</option>
                        {else}
                        <option value="{$val.id}">{$val.name}</option>
                      
                        {/if}
                    {/foreach}
                </select>

            
            </div> -->


            
            <div class="layui-input-block">
                {if (@$vo.user_name)}
                    <input  style="position: absolute;z-index:2;width: 80%;" autocomplete="off" name="user_name" value='{$vo.user_name|default=""}' required placeholder="搜索入姓名" class="layui-input" id="searchname">
                {else}
                    <input style="position: absolute;z-index:2;width: 80%;" autocomplete="off" name="user_name" value='{$vo.user_name|default=""}' required placeholder="搜索输入姓名" class="layui-input" id="searchname">
                {/if}           
                 <select id="searchuserlist"  class="layui-input layui-unselect" name="createuid" lay-filter="watch" lay-search>
                    {if (@$vo.user_name)}
                        <option value="{$vo.createuid}">{$vo.user_name}</option>
                    {else}
                         <option value="">-- 搜索姓名 --</option>
                    {/if}   
               


                </select>

            </div>


        </div>
        <div class="layui-form-item">
            <label class="layui-form-label label-required">公司负责人姓名</label>
            <div class="layui-input-block">
                {if @$vo.corporation}
                    <input readonly name="corporation" value='{$vo.corporation|default=""}' required placeholder="公司负责人" class="layui-input">
                {else}
                    <input name="corporation" value='' required placeholder="公司负责人" class="layui-input">    
                {/if}
            </div>
        </div>

                <div class="layui-form-item">
            <label class="layui-form-label label-required">公司负责人联系电话</label>

            <div class="layui-input-block">
                {if (@$vo.company_mobile)}
                <input  required id="searchphone" style="position: absolute;z-index:2;width: 80%;" type="tel" maxlength="11" autocomplete="off" name="mobile" value='{$vo.company_mobile|default=""}' pattern="^1[3-9][0-9]{9}$" placeholder="请输入联系手机" class="layui-input">
                {else}
                <input  required id="searchphone" style="position: absolute;z-index:2;width: 80%;" type="tel" maxlength="11" autocomplete="off" name="mobile" value='{$vo.company_mobile|default=""}' pattern="^1[3-9][0-9]{9}$" placeholder="请输入联系手机" class="layui-input">
                {/if}
                 <select id="searchphonelist"  class="layui-input layui-unselect" name="mobile" lay-filter="watchphone" lay-search>
                    {if (@$vo.company_mobile)}
                        <option value="{$vo.id}">{$vo.company_mobile}</option>
                    {else}
                         <option value="">-- 搜索手机号 --</option>
                    {/if}   
               
                </select>
            </div>

        </div>


        <div class="layui-form-item">
            <label class="layui-form-label label-required">公司地址</label>
            <div class="layui-input-block">
                {if @$vo.address}
                <input {if $userinfo['db1']['authorize'] =='8'}readonly{/if} name="address" value='{$vo.address|default=""}'  placeholder="公司地址" class="layui-input">
                {else}
                <input name="address" value='' required placeholder="公司地址" class="layui-input">
                {/if}
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label label-required">公司营业执照</label>

            <div class="layui-input-block">

                <div class="layui-textarea padding-bottom-10" style="min-height:auto">

                <span id="upload-btn-tips" class="color-green">(是否上传营业执照)</span>
                <input checked lay-filter="upye_switch" type="checkbox" name="upye_switch" lay-skin="switch">



                <div id="NewsEditor" class="layui-clear nowrap padding-bottom-30">
                <span class="color-green">(营业执照-缩略图)</span>
                {notempty name='vo.imgurl'}
               {php}
               {
            
                if (strstr($vo['imgurl'],'http://pc.zsicp.com')){
                    echo  "<img name="."old_imgurl"." data-tips-image style="."max-width:120px;height:60px;vertical-align:top"." src=".$vo['imgurl']." class="."margin-right-5".">";

                  echo "<input data-auto-none value=".$vo['imgurl']." type="."hidden"." name="."old_imgurl".">";
                }else{
 

                    echo  "<img name="."old_imgurl"." data-tips-image style="."max-width:120px;height:60px;vertical-align:top"." src="."http://devs.zsicp.com/public/upload/business_license/".$vo['imgurl']." class="."margin-right-5".">";

                    echo "<input data-auto-none value=".$vo['imgurl']." type="."hidden"." name="."old_imgurl".">";
                }
            
                }
               {/php}



<!--     <label class="layui-form-label">使用原有营业执照</label>
    <div class="layui-input-block" >
      <input lay-filter="ye_switch" type="checkbox" name="ye_switch" lay-skin="switch">
    </div> -->
                {/notempty}
                <div class="layui-form-item label-required-prev upload_yye">

                    <div class="layui-clear">
  
                        <div class="upload-image-box pull-left transition" data-tips-image="{{item.local_url}}" style="{{item.style}}">
                            <input ng-model="item.local_url" data-auto-none value="{{item.local_url}}" type="hidden" name="local_url">
                        </div>
                        <div class="pull-left padding-top-15 padding-left-15">
                           
                            <button type="button" data-title="上传营业执照" data-file="btn" data-type="jpg,png,jpeg" data-field="local_url" class="layui-btn layui-btn-sm layui-btn-primary">
                            {if @$vo.id}
                            重新上传营业执照
                            {else}
                            上传营业执照
                            {/if}
                        </button>


                            <br>
                        </div>
                    </div>
                    <p class="color-desc">封面大图片建议尺寸 900像素 * 500像素</p>
                </div>
                </div>
                </div>
            </div>
        </div>
        {if @$vo.id}
        <div class="layui-form-item">
            <label class="layui-form-label">公司套餐信息</label>

            <div class="layui-input-block">

                <div class="layui-textarea padding-bottom-10" style="min-height:auto">

          <div class="layui-form-item font-size-20">
              <label class="relative block">
                 <!--  <span class="color-green font-w7">会员信息</span> -->
                  <span class="color-desc margin-left-5">Member</span>
                  <p class="margin-left-5">

                  {if @$data.member_info}
                    {if condition="($data.member_info.vip_level eq 0)"}
                      <span class="color-blue">访客会员</span>
                       {elseif condition="($data.member_info.vip_level eq 1)"/}
                       <span class="color-blue">租户会员</span>
                        {elseif condition="($data.member_info.vip_level eq 2)"/}
                        <span class="color-blue">物业会员</span>
                         {elseif condition="($data.member_info.vip_level eq 3)"/}
                         <span class="color-blue">企业会员</span>
                         {else /}
                    {/if}
                  </br>

                  {if condition="($data.member_info.year neq 0)"}
                      <span class="color-blue">套餐类型: {$data.member_info.year|default=''}/年付</span>
                    {elseif condition="($data.member_info.month neq 0)"/}
                      <span class="color-blue">套餐类型: {$data.member_info.month|default=''}/月付</span>
                    {elseif condition="($data.member_info.day neq 0)"/}
                      <span class="color-blue">套餐类型: {$data.member_info.day|default=''}/日付</span>
                    {else /}
                  {/if}
                </br>
                  <span class="color-blue">续费日期:{$data.member_info.vip_date|default=''}</span>
                    {else}
                      暂无信息
                  {/if}

                </p>
                 <!--   <input readonly value="{$storememberinfo['title']|default=''}" class="layui-input layui-bg-gray"> -->
                

              </label>  
              <p class="help-block"></p>
          </div>

                </div>
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label class="layui-form-label">操作选项</label>

            <div class="layui-input-block">

                <div class="layui-textarea padding-bottom-10" style="min-height:auto">
            {if @$vo.id}
            <div class="layui-row layui-col-space10">
              <div class="layui-col-md3">
                  <button type="button" data-modal="{:url('invitation/invitation/index')}?spm=m-73-74-75&company_id={$vo.id}" data-title="查看企业邀请" class='layui-btn layui-btn-sm  layui-btn-normal'>查看企业邀请</button>
              </div>
             <div class="layui-col-md3">
                  <button type="button" data-modal="{:url('visitor/visitor/index')}?spm=m-70-71-72&company_id={$vo.id}" data-title="查看企业访客" class='layui-btn layui-btn-sm  layui-btn-normal'>查看企业访客</button>
             </div>
<!--             <div class="layui-col-md4">
              1/3
            </div> -->
             {if auth("remove")}
              <div class="layui-col-md3">
                <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除租户吗?(删除租户不删除租户信息)" data-action="{:url('remove')}" data-value="id#{$vo.id}" data-csrf="{:systoken('remove')}" action="{:url('company/remove')}">删除该租户</a>
              </div>
                {/if}
            </div>

                  {/if}

                </div>
            </div>
        </div>

    </div>

    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>

    <script>

    window.form.render();

</script>
</form>
<script type="text/javascript">
        require(['angular', 'ckeditor'], function () {

        var $form = $('form[name="news"]');
        var $vali = $form.vali().data('validate');
        // var editor = window.createEditor('[name="content"]');
        var app = angular.module("NewsEditor", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        form.on('switch(upye_switch)', function(data){
        //     console.log(data.elem); //得到checkbox原始DOM对象
        // 　　console.log(data.elem.checked); //开关是否开启，true或者false
        // 　　console.log(data.value); //开关value值，也可以通过data.elem.value得到
        // 　　console.log(data.othis); //得到美化后的DOM对象
            if(!data.elem.checked){

                $('.upload_yye').css({'display':'none'});
             }else{
                $('.upload_yye').css({'display':'block'});
                }
        });

        /**选择用户后**/
        form.on('select(watch)', function(data){
              $.ajax({
                url:"{:url('company/user/getuserlist')}",
                data:{id:data.value},
                type:'post',
                async: false,
                dataType:'json',
                success:function(res) {
                  var reres = JSON.parse(res)
                  if(reres.data.roleid==2){
                    $('.authorize-changer').css({'display':'block'})
                  }else{
                    $('.authorize-changer').css({'display':'none'})
                    $('input[name="ch_role"]').val('off');
                  }
                  $('#searchname').val(reres.data.name)
                  $("input[name='mobile']").val(reres.data.mobile)
                  //$("input[name='userid']").val(reres.data.id)
                }
            })
          });
          /**选择手机后**/
        form.on('select(watchphone)', function(data){
              $.ajax({
                url:"{:url('company/user/getuserlist')}",
                data:{id:data.value},
                type:'post',
                async: false,
                dataType:'json',
                success:function(res) {
                  var reres = JSON.parse(res)
                  if(reres.data.roleid==2){
                    $('.authorize-changer').css({'display':'block'})
                  }else{
                    $('.authorize-changer').css({'display':'none'})
                    $('input[name="ch_role"]').val('off');
                  }
                  $('#searchname').val(reres.data.name)
                  $("input[name='mobile']").val(reres.data.mobile)
                  $("#searchphone").val(reres.data.mobile)
                  //$("input[name='userid']").val(reres.data.id)
                  $('#searchuserlist').val(reres.data.id)

                  $('#searchuserlist').after("<input type='hidden' value='"+reres.data.id+"' name='createuid'>");
                }
            })
          });

        /**搜索人名监听**/
        $("#searchname").on("input",function(e){
            $("#searchuserlist").next().find("dl").css({ "display": "block" });
            $('#searchuserlist').html('')
            form.render('select')
            if(e.delegateTarget.value==''){return;}
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{name:e.delegateTarget.value},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                var option = ''
                for (var i = 0; i < reres.data.length; i++) {
                    option = option+"<option value="+reres.data[i].id+">"+reres.data[i].name+"</option>"
                }

                $('#searchuserlist').append(option)
              }
          })
            form.render('select')
        });
        /**搜索电话监听**/
        $("#searchphone").on("input",function(e){
            $("#searchphonelist").next().find("dl").css({ "display": "block" });
            $('#searchphonelist').html('')
            form.render('select')
            if(e.delegateTarget.value==''){return;}
            $.ajax({
              url:"{:url('company/user/getuserlist')}",
              data:{'phone':e.delegateTarget.value,'type':'phone'},
              type:'post',
              async: false,
              dataType:'json',
              success:function(res) {
                var reres = JSON.parse(res)
                var option = ''
                for (var i = 0; i < reres.data.length; i++) {
                    option = option+"<option value="+reres.data[i].id+">"+reres.data[i].mobile+"</option>"
                }
                $('#searchphonelist').append(option)
              }
          })
            form.render('select')
        });

        function callback($rootScope) {
            $rootScope.list = [];
            $rootScope.item = {};

            $rootScope.setItemValue = function (name, value) {

                $rootScope.item[name] = value;
                $rootScope.item.style = "background-image:url('" + $rootScope.item.local_url + "')";

                $.post("{:url('personal/personal/upload')}", {'local_url':value}, function(result) {
                 
                  result = JSON.parse(result)

                  if (result.code == 200) {
                      //成功
                      $('input[name="companyname"]').val(result.data.name)
                      $('input[name="code"]').val(result.data.code)
                      $('input[name="address"]').val(result.data.address)
                      $('input[name="corporation"]').val(result.data.corporation)
                      return $.msg.success(result.message);
                  } else if (result.code == 400) {
                      // 失败
                      return $.msg.error(result.message);
                  }
                      }, "JSON");

            };

            $('[name="local_url"]').on('change', function () {
                var value = this.value;
                $rootScope.$apply(function () {
                    $rootScope.setItemValue('local_url', value);
                });
            });
        }
    });

</script>

